import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

/**
 * @Author wonghiu
 * @Date 2021/8/8 19:45
 * @Version 1.0.1
 *
 * 3 1
 * 1 2 3
 *
 * 1 2 3
 * 1 3 2
 * 2 1 3
 * 3 2 1
 */
public class pdd3 {
    static int resCount = 0;
    static private LinkedList<Integer> path = new LinkedList<>();
    static int[] visit;
    public static void main(String[] args) {
//        Scanner sc = new Scanner(System.in);
//        int n = sc.nextInt();
//        int m = sc.nextInt();
//        int[] input = new int[n];
//        for (int i = 0; i < n; i++) {
//            input[i] = sc.nextInt();
//        }
        int m = 1;
        int[] input = new int[]{1,2,3,4};
        count(input,m);
        System.out.println(resCount);
    }

    private static void count(int[] input,int m) {
        visit = new int[input.length];
        dfs(input,0,input.length-1,m);
    }

    private static void dfs(int[] nums,int start,int end,int m) {
        System.out.println(path);
        if (path.size()==nums.length){
            resCount++;
            return;
        }

        for (int i = start; i <= end; i++) {
            if (visit[i]==1){continue;}
            if (path.isEmpty() || path.getLast()-nums[i]<=m) {
                visit[i]=1;
                path.addLast(nums[i]);
                dfs(nums, start, end, m);
                path.removeLast();
                visit[i] = 0;
            }else {
                continue;
            }
        }
    }

}
